<?php
header("content-type:text/html;charset=utf8");
$pdo = new PDO("mysql:host=127.0.0.1;dbname=1607phpc","root","root");
$city = $_POST['city'];
$url = "http://api.k780.com:88/?app=weather.future&weaid=$city&&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json请求方式";
$data = file_get_contents($url);
// echo $data;die;
$data = json_decode($data,true);
$result = $data['result'];
// print_r($result);die;
foreach ($result as $key => $value) {
	$city = $value['citynm'];
	$week = $value['week'];
	$temp_high = $value['temp_high'];
	$temp_low = $value['temp_low'];
	$temperature = $value['temperature'];
	$sql = "insert into weather values('','$city','$week','$temp_high','$temp_low','$temperature')";
	$res = $pdo->exec($sql);

}
if($res){
	$data = array('code'=>1,'msg'=>"成功");
}else{
	$data = array('code'=>1,'msg'=>"失败");
}
echo json_encode($data);